package com.supply.dl.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;

import com.supply.dl.app.AppConfig;

/**
 * Created by ${qianzhihe} on 2018/5/7.
 * 存储卡管理类
 */

public class StorageUtil {
    public static final String EXTERNAL_STORAGE = Environment.getExternalStorageDirectory().toString();

    /**
     * 保存登录状态
     *
     * @param context
     * @param isLogin：true--已登录；false--未登录
     */
    public static void saveLoginState(Context context, boolean isLogin) {
        SharedPreferences preferences = context.getSharedPreferences(
                AppConfig.SP_NAME, Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(AppConfig.LOGIN_STATE, isLogin);
        editor.commit();
    }

    public static boolean getLoginState(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(
                AppConfig.SP_NAME, Context.MODE_MULTI_PROCESS);
        return preferences.getBoolean(AppConfig.LOGIN_STATE, false);
    }

    /**
     * 保存登录成功后的token
     * @param context
     * @param token
     */
    public static void saveUserToken(Context context, String token) {
        SharedPreferences preferences = context.getSharedPreferences(
                AppConfig.SP_NAME, Context.MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(AppConfig.TOEKN, token);
        editor.commit();
    }

    public static String getUserToken(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(
                AppConfig.SP_NAME, Context.MODE_MULTI_PROCESS);
        return preferences.getString(AppConfig.TOEKN, "");
    }

}
